<template>
  <view class="loading-container" :class="{ overlay: isOverlay, center: isCenter }">
    <view class="loading-content">
      <view class="loading-spinner" :class="type">
        <view v-if="type === 'dots'" class="dot" v-for="i in 3" :key="i"></view>
        <view v-else-if="type === 'circular'" class="circular"></view>
        <view v-else class="pulse"></view>
      </view>
      <text v-if="text" class="loading-text">{{ text }}</text>
    </view>
  </view>
</template>

<script setup>
defineProps({
  text: {
    type: String,
    default: '加载中...'
  },
  type: {
    type: String,
    default: 'circular', // 'circular', 'dots', 'pulse'
    validator: (val) => ['circular', 'dots', 'pulse'].includes(val)
  },
  isOverlay: {
    type: Boolean,
    default: false
  },
  isCenter: {
    type: Boolean,
    default: true
  }
});
</script>

<style lang="scss" scoped>
.loading-container {
  padding: 30rpx;
  
  &.overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.8);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  &.center {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  
  .loading-text {
    margin-top: 20rpx;
    font-size: 26rpx;
    color: var(--text-secondary);
  }
  
  .loading-spinner {
    &.dots {
      display: flex;
      align-items: center;
      justify-content: center;
      
      .dot {
        width: 16rpx;
        height: 16rpx;
        border-radius: 50%;
        background-color: var(--primary-color);
        margin: 0 8rpx;
        animation: dotBounce 1.4s infinite ease-in-out both;
        
        &:nth-child(1) {
          animation-delay: -0.32s;
        }
        
        &:nth-child(2) {
          animation-delay: -0.16s;
        }
      }
    }
    
    &.circular {
      width: 60rpx;
      height: 60rpx;
      border: 4rpx solid rgba(24, 144, 255, 0.1);
      border-top-color: var(--primary-color);
      border-radius: 50%;
      animation: spin 1s infinite linear;
    }
    
    &.pulse {
      width: 60rpx;
      height: 60rpx;
      background-color: var(--primary-color);
      border-radius: 50%;
      animation: pulse 1.2s infinite cubic-bezier(0.4, 0, 0.2, 1);
    }
  }
}

@keyframes dotBounce {
  0%, 80%, 100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

@keyframes pulse {
  0% {
    transform: scale(0);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 0;
  }
}
</style> 